package ua.epam.muzalevskiy.traction.commands;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ua.epam.muzalevskiy.traction.configuretion.PagePathConfigurer;

/**
 * <code>LogoutCommand</code> class is the <code>Command</code> 
 * interface implementation, that realized <code>Command</code> pattern.
 * Current class encapsulate action of user logout from system.
 * 
 * @author Muzalevskiy Vitaliy
 * @see Command
 * @see User
 * @see RegisteredUser
 */
public class LogoutCommand implements Command {
    
    private static final String SESSION_ATTRIBUTE_NAME_USER_TYPE = "user_type";

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        request.getSession().setAttribute(SESSION_ATTRIBUTE_NAME_USER_TYPE, null);
        String page = PagePathConfigurer.getInstance()
                .getProperty(PagePathConfigurer.INDEX_PAGE);
        return page;
    }
}
